package com.hanxiaozhang.oauth2.controller;


import com.hanxiaozhang.oauth2.service.MenuService;
import com.hanxiaozhang.oauth2.service.TokenService;
import com.hanxiaozhang.oauth2.service.UserService;
import com.hanxiaozhang.oauth2.utils.R;
import com.hanxiaozhang.oauth2.utils.SecuityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.token.ConsumerTokenServices;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 功能描述: <br>
 * 〈〉
 *
 * @Author:hanxinghua
 * @Date: 2020/7/27
 */
@RequestMapping()
@RestController
public class LoginController {

    @Autowired
    UserService userService;

    @Autowired
    TokenService tokenService;

    @Autowired
    MenuService menuService;

    @Autowired
    private ConsumerTokenServices consumerTokenServices;


    /**
     * 获取该用户的菜单
     *
     * @return
     */
    @GetMapping("/router")
    R router() {
        return R.ok().put("router", menuService.RouterDTOsByUserId(SecuityUtils.getCurrentUser().getId()));
    }


    @RequestMapping("/logout")
    R logout(String token) {
        consumerTokenServices.revokeToken(token);
        return R.ok();
    }


}
